import java.util.ArrayList;
//import java.util.Map;
//import java.util.HashMap;



public class UserData
{
    //Instance Variables
    String id;
    String gender;
    String age;
    String country;
    String registered;
    ArrayList<ArtistData> topArtists;
    
    //Filter variable.
    int filterChecked;
    
    //Default Constructor
    public UserData()
    {
        
    }
    public UserData(String userId,String userGender,String userAge,String userCountry,String userRegistered)
    {
        id = userId;
        gender = userGender;
        age = userAge;
        country = userCountry;
        registered = userRegistered;
        topArtists = new ArrayList<ArtistData>();
        filterChecked=0;
    }
	
    public void fixEmpty()
    {
	if(id.isEmpty())
	{
	    id = "N";
	}
		
	if(gender.isEmpty())
	{
	    gender = "N";
	}
		
	if(age.isEmpty())
	{
	    age = "N";
	}
		
	if(country.isEmpty())
	{
	    country = "N";
	}
		
	if(registered.isEmpty())
	{
	    registered = "N";
	}
    }

    public void addArtist(ArtistData artist)
    {
        topArtists.add(artist);
    }
    
    public boolean validCountry(ArrayList<String> countryList)
    {
        boolean result = true;
        for(int index=0; index < countryList.size();index++)
        {
            if(country.equals(countryList.get(index)))
            {
                result = false;
            }
        }
        return result;
    }
    
    public boolean checkValid(Filters dataFilter)
    {
    	if(filterChecked == 1)
    	{
    		return true;
    	}
    	else if(filterChecked == 2)
    	{
    		return false;
    	}
    	
        if(dataFilter.countryFilter)
        {
            //Walk through countries.
            for(int index=0; index < dataFilter.countryList.size();index++)
            {
                if(!country.equals(dataFilter.countryList.get(index)))
                {
                	filterChecked = 2;
                    return false;
                }
            }
        }
        
        if(dataFilter.sexFilter)
        {
            //Check sex
            if(dataFilter.sexFilterValue == 1 && this.gender.equals("m"))
            {
            	filterChecked = 2;
                return false;
            }
            else if(dataFilter.sexFilterValue == 2 && this.gender.equals("f"))
            {
            	filterChecked = 2;
                return false;
            }
        }
        
        if(dataFilter.ageFilter)
        {
            //Check the age is in the bounds.
            int userAge = 0;
           		if(!this.age.equals("N")) 
           			userAge = Integer.parseInt(this.age);
           		
            if((userAge < dataFilter.ageFilterValue[0]) || (userAge > dataFilter.ageFilterValue[1]))
            {
            	filterChecked = 2;
                return false;
            }
        }
        
        //Apparently this user has passed all of its checks.
        filterChecked = 1;
        return true;
    }
    
    
    public String getName()
    {
        return id;
    }
    
    public String getSex()
    {
    	return gender;
    }
    
    public String getAge()
    {
    	return age;
    }
    
    public String getCountry()
    {
    	return country;
    }
    
    public int getArtistNumber()
    {
    	return topArtists.size();
    }
    
    //Return 1 if Female, 2 if Male
    public int getSexInt() {
    	if(gender.equalsIgnoreCase("f"))
    		return 1;
    	return 2;
    }
    
    //Return age in form of an int
    //	returns 0 when no age is given
    public int getAgeInt() {
    	if(!age.equalsIgnoreCase("n"))
    		return Integer.parseInt(age);
    	return 0;
    }
    
    public void resetFilterCheck()
    {
    	filterChecked = 0;
    }
    
    public int artistSize()
    {
    	return topArtists.size();
    }
    
    
    public String toString()
    {
        String sp = "\t";
        //#id	gender	age	country	registered
        return id + sp + gender + sp + age + sp + country + sp + registered;
    }
}